<?php include('header.php');?>
<body>
<div class="box">
  <div class="left"></div>
  <div class="right"></div>
    <div class="heading"><h1>แก้ไขการจอง</h1>
    <div class="buttons"><a onclick="Javascript:window.location='room_edit.php';" class="button"><span>ยกเลิก</span></a></div>
</div>
<div class="content">
<?php 
if($_POST['rtype']=='name'){
	$name = explode(" ", $_POST['Name']);
	$rQuery = mysql_query("SELECT reservation_detail_id FROM reservation_detail WHERE reservation_detail_fname = '$name[0]' AND reservation_detail_lname = '$name[1]'");
}

if($_POST['rtype']=='day'){
	$dmy = $_POST["dateInput"];
	$day = substr($dmy, 0, 2);
	$month = substr($dmy, 3, 2);
	$y = substr($dmy, 6, 4);
	$year = $y-543;
	$date = $year."-".$month."-".$day;
	$rQuery = mysql_query("SELECT reservation_detail.reservation_detail_id as reservation_detail_id,reservation_detail.reservation_detail_fname as reservation_detail_fname,reservation_detail.reservation_detail_lname as reservation_detail_lname FROM reservation_detail,reservation WHERE reservation_detail.reservation_detail_id=reservation.reservation_detail_id AND reservation.reservation_checkin = '$date' GROUP BY reservation.reservation_detail_id");
}


if(mysql_num_rows($rQuery)==0){
?>
      <br /><center><h2><?php echo $_POST['Name']; ?> ไม่มีข้อมูลนี้ค่ะ กรุณากลับไปแก้ไขใหม่อีกครั้ง!!</h2></center>
<?php
} else {
?>
<h3><?php if($_POST['Name']!=""){ echo $_POST['Name'];} ?></h3>
<div style="padding: 10px 30px 0px 40px;">
<?php 
while($rRow = mysql_fetch_array($rQuery)){
?>
<h3><?php echo $rRow['reservation_detail_fname']." ".$rRow['reservation_detail_lname'];?><br>รหัสจอง  RE<?php echo sprintf("%08d", $rRow['reservation_detail_id']);?> <a href="room_edit_show_add.php?id=<?php echo $rRow['reservation_detail_id'];?>" title="แก้ไขการจอง">แก้ไข</a></h3> 
<table class="list2" width="700px">
	<thead>
	<tr>
		<td width="1px" class="center">ลำดับ</td>
		<td width="170px" class="center">วันที่เข้าพัก</td>
		<td class="center">ห้องพักที่จอง</td>
	</tr>
	</thead>
<?php 
	$sQuery = mysql_query("SELECT reservation_checkin FROM reservation WHERE reservation_detail_id = '".$rRow['reservation_detail_id']."' GROUP BY reservation_checkin ORDER BY reservation_checkin");
		$num=0;
	while($sRow = mysql_fetch_array($sQuery)){
		$dQuery = mysql_query("SELECT room.room_name as room_name,room.room_pax as room_pax FROM reservation,room WHERE room.room_id = reservation.room_id AND reservation.reservation_checkin = '".$sRow['reservation_checkin']."' AND reservation.reservation_detail_id = '".$rRow['reservation_detail_id']."' ");
		$roomNum = 0;
		while($dRow = mysql_fetch_array($dQuery)){
			$roomNum++;
			$room_name .= ", ".$dRow['room_name'];
			//$Room_Pax = $Room_Pax + $dRow['room_pax'];
		}
		$num++;
?>
	<tr>
		<td valign="top" class="center"><?php echo $num;?></td>
		<td valign="top" class="right"><?php echo ThaiDate2(strtotime($sRow['reservation_checkin']));?></td>
		<td valign="top" style="padding-left: 20px;" class="left"><?php echo "<b> (".$roomNum." ห้อง)</b> ".substr($room_name, 2);?></td>
	</tr>
<?php 
		$room_name = "";
	} ?>
</table>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
</body>
<?php include('footer.php');?>
